//
//  HomeChoiceProvinceVc.m
//  QuickCure1
//
//  Created by Ashzenki on 02/11/2016.
//  Copyright © 2016 maoge. All rights reserved.
//

#import "HomeChoiceProvinceVc.h"
#import "HomeChoiceCityVc.h"
#import "HomeProvinceModel.h"

@interface HomeChoiceProvinceVc ()

@end

@implementation HomeChoiceProvinceVc

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
    
    //取消分割线
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    self.tableView.rowHeight = 50;
    
    [self loadData];
    
    self.navigationItem.title = @"选择省份";
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor blackColor],
                                                                    NSFontAttributeName:MYFONT(18)};
    
    [self setUpLeftButtonItem];
}

- (void)setUpLeftButtonItem{
    
    UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    [leftBtn setImage:[UIImage imageNamed:@"jiantou"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
}

- (void)goBack{
    
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 加载数据

- (void)loadData {
    
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"province.plist" ofType:nil];
    
    NSArray *arr = [NSArray arrayWithContentsOfFile:filePath];
    
    _modelList = [NSArray yy_modelArrayWithClass:[HomeProvinceModel class] json:arr];
    
//    NSLog(@"%@", _modelList);
}



#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return _modelList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    HomeProvinceModel *model = _modelList[indexPath.row];
    
    cell.textLabel.text = model.name;
    
    cell.textLabel.font = MYFONT(18);
    
    //设置分割线
    UIImageView *separatView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"table_item_bk_with_top_gray_corner"]];
    [cell.contentView addSubview:separatView];
    
    [separatView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.equalTo(cell.contentView);
        make.height.mas_equalTo(5);
    }];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    HomeChoiceCityVc *vc = [[HomeChoiceCityVc alloc] init];
    
    HomeProvinceModel *model = _modelList[indexPath.row];
    
    vc.CityList = model.cities;
    
    [self.navigationController pushViewController:vc animated:YES];
    
}

- (void)dealloc {
    
    NSLog(@"选择省份释放了");
}


@end


































